//
//  AccountCenterPayModeView.m
//  JiaoX
//
//  Created by jiaoxiu－005 on 15/1/20.
//  Copyright (c) 2015年 北京娇羞科技有限公司. All rights reserved.
//

#import "AccountCenterPayModeView.h"
#define ACCOUNT_CENTER_PAYMODE_VIEW_DESC [DimensUtils getScaleX:15]
#define ACCOUNT_CENTER_PAYMODE_VIEW_CONDITION [DimensUtils getScaleX:12]
@interface AccountCenterPayModeView()
@property(nonatomic,strong) UIImageView *payModeIconView;
@property(nonatomic,strong) UILabel *payModeDesc;
@property(nonatomic,strong) UILabel *payModeCondition;
@property(nonatomic,strong) UIButton *isCheckBtn;
@property(nonatomic,strong) UIView *downlineView;

@end

@implementation AccountCenterPayModeView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setBounds:CGRectMake(0, 0, JXScreenW, 57)];
        
        //1.图标
        UIImageView *payModeIconView = [[UIImageView alloc]init];
        UIImage *payModeIcon = [UIImage imageNamed:@"account_center_alipay_icon"];
        [payModeIconView setImage:payModeIcon];
        [payModeIconView setFrame:CGRectMake(JXPublicInset, JXPublicInset, payModeIcon.size.width, payModeIcon.size.height)];
        _payModeIconView = payModeIconView;
        [self addSubview:payModeIconView];
        
        //2.描述
        UILabel *payModeDesc =[[UILabel alloc]init];
        NSString *payModeDescText = @"货到付款";
        [payModeDesc setText:payModeDescText];
        [payModeDesc setTextColor:JXColor(0, 0, 0)];
        [payModeDesc setFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_PAYMODE_VIEW_DESC]];
        CGSize payModeDescTextSize = [payModeDescText sizeWithFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_PAYMODE_VIEW_DESC]];
        [payModeDesc setFrame:CGRectMake(CGRectGetMaxX(self.payModeIconView.frame)+JXPublicInset, 18, payModeDescTextSize.width, payModeDescTextSize.height)];
        _payModeDesc = payModeDesc;
        [self addSubview:payModeDesc];
        
       
        //4.状态
        UIButton *isCheckBtn =[[UIButton alloc]init];
        UIImage *norImg = [UIImage imageNamed:@"account_center_no_select_pay_mode"];
        UIImage *selectImg = [UIImage imageNamed:@"account_center_select_pay_mode"];
        [isCheckBtn setBackgroundImage:norImg forState:UIControlStateNormal];
        [isCheckBtn setBackgroundImage:selectImg  forState:UIControlStateSelected];
        [isCheckBtn setFrame:CGRectMake(JXScreenW-norImg.size.width-JXPublicInset, (57-norImg.size.height)/2, norImg.size.width, norImg.size.height)];
        _isCheckBtn = isCheckBtn;
        [self addSubview:isCheckBtn];
        
        //3.包邮条件
        UILabel *payModeCondition =[[UILabel alloc]init];
        NSString *payModeConditionText = @"满169元包邮";
        [payModeCondition setText:payModeConditionText];
        [payModeCondition setTextAlignment:NSTextAlignmentRight];
        [payModeCondition setTextColor:JXColor(153, 153, 153)];
        [payModeCondition setFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_PAYMODE_VIEW_CONDITION]];
        CGSize payModeConditionTextSize = [payModeConditionText sizeWithFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_PAYMODE_VIEW_CONDITION]];
        [payModeCondition setFrame:CGRectMake(JXScreenW-norImg.size.width-payModeConditionTextSize.width-JXPublicInset*2, 21, payModeConditionTextSize.width, payModeConditionTextSize.height)];
        _payModeCondition = payModeCondition;
        [self addSubview:payModeCondition];
        
        //5.添加下划线
        UIView * downlineView = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.payModeIconView.frame)+JXPublicInset, CGRectGetMaxY(self.payModeIconView.frame)+JXPublicInset, JXScreenW-CGRectGetMaxX(self.payModeIconView.frame)+JXPublicInset, 0.5)];
        [downlineView setBackgroundColor:JXColor(204, 204, 204)];
        _downlineView = downlineView;
    
        UITapGestureRecognizer *clickGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickPayMode)];
        [self addGestureRecognizer:clickGesture];
        [self addSubview:downlineView];
    }
    return self;
}

//设置图标
-(void)setIcon:(NSString *)icon{
     UIImage *payModeIcon = [UIImage imageNamed:icon];
    [self.payModeIconView setImage:payModeIcon];
}
//设置描述
-(void)setDesc:(NSString *)desc{
    [self.payModeDesc setText:desc];
}
//设置包邮条件
-(void)setCondition:(NSString *)condition{
    [self.payModeCondition setText:condition];
}
//设置是否选中
-(void)setIsChecked:(BOOL)isChecked{
    [self.isCheckBtn setSelected:isChecked];
}
//是否显示下划线
-(void)setIsHidenLine:(BOOL)isHidenLine{
    [self.downlineView setHidden:isHidenLine];
}
-(void)clickPayMode{
    if ([self.delegate respondsToSelector:@selector(clickPayMode:)]) {
        [_delegate clickPayMode:self.tag];
    }
}

@end
